package com.villaday.idf.adapter3;

import android.content.Context;
import android.view.View;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.model3.MemberGuestEntity;
import com.villaday.idf.util.PhoneUtil;

public class CommonAdapter extends AbsRecyclerViewAdapter<MemberGuestEntity.BodyBean> {

    View.OnClickListener onClickListener;
    View.OnLongClickListener mOnLongClickListener;
    public CommonAdapter(Context context, View.OnClickListener onClickListener, View.OnLongClickListener mOnLongClickListener) {
        super(context, R.layout.recycle_common);
        this.onClickListener = onClickListener;
        this.mOnLongClickListener = mOnLongClickListener;
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, MemberGuestEntity.BodyBean d, int position) {
        try {
            String nameEn = d.getGivenNameEn() != null && d.getGivenNameEn().length() != 0
                    && d.getFamilyNameEn() != null && d.getGivenNameEn().length() != 0
                    ? d.getFamilyNameEn() + "/" + d.getGivenNameEn() : " ";
            holder.bindTextView(R.id.tv_c_name, d.getNameCn() + "  " + nameEn);

            if (d.getIdcard() != null) {
                holder.getView(R.id.ll_c_card).setVisibility(View.VISIBLE);
                holder.bindTextView(R.id.tv_c_card, d.getIdcardEnc());
            } else {
                holder.getView(R.id.ll_c_card).setVisibility(View.GONE);
            }

            if (d.getMobile() != null) {
                holder.getView(R.id.ll_c_phone).setVisibility(View.VISIBLE);
                holder.bindTextView(R.id.tv_c_phone, d.getMobileEnc());
            } else {
                holder.getView(R.id.ll_c_phone).setVisibility(View.GONE);
            }

            if (d.getEmail() != null) {
                holder.getView(R.id.ll_c_email).setVisibility(View.VISIBLE);
                holder.bindTextView(R.id.tv_c_email, d.getEmailEnc());
            } else {
                holder.getView(R.id.ll_c_email).setVisibility(View.GONE);
            }

            if (d.getEmail() == null && d.getPassport() == null && d.getMobile() == null && d.getIdcard() == null) {
                holder.getView(R.id.iv_c_more).setVisibility(View.VISIBLE);
                holder.getView(R.id.iv_c_retire).setVisibility(View.GONE);
                holder.getView(R.id.tv_common_more).setVisibility(View.VISIBLE);
            } else {
                holder.getView(R.id.iv_c_more).setVisibility(View.GONE);
                holder.getView(R.id.tv_common_more).setVisibility(View.GONE);
                holder.getView(R.id.iv_c_retire).setVisibility(View.VISIBLE);
            }


            holder.getView(R.id.iv_c_retire).setTag(position);
            holder.getView(R.id.iv_c_retire).setOnClickListener(onClickListener);
            holder.getView(R.id.iv_c_retire).setOnLongClickListener(mOnLongClickListener);

            holder.getView(R.id.tv_common_more).setTag(position);
            holder.getView(R.id.tv_common_more).setOnClickListener(onClickListener);
            holder.getView(R.id.tv_common_more).setOnLongClickListener(mOnLongClickListener);

            holder.getView(R.id.iv_c_more).setTag(position);
            holder.getView(R.id.iv_c_more).setOnClickListener(onClickListener);
            holder.getView(R.id.iv_c_more).setOnLongClickListener(mOnLongClickListener);

            if (data.size() == position + 1) {
                holder.getView(R.id.vw_common).setVisibility(View.VISIBLE);
            } else {
                holder.getView(R.id.vw_common).setVisibility(View.GONE);
            }


            if (d.getPassport() != null) {
                holder.getView(R.id.ll_c_passport).setVisibility(View.VISIBLE);
                holder.bindTextView(R.id.tv_c_passport, PhoneUtil.getPassport(d.getPassport()));
            } else {
                holder.getView(R.id.ll_c_passport).setVisibility(View.GONE);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
